package com.itboye.eweilisten.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.itboye.eweilisten.R;
import com.itboye.eweilisten.model.OldBean;

import java.util.List;

/**
 * Created by itboye on 2017/3/9.
 */

public class OldAdapter extends BaseAdapter {
    Context context;
    List<OldBean> bean;
    private int selectedPosition=-1;

    public OldAdapter(Context context, List<OldBean> bean) {
        this.context=context;
        this.bean=bean;
    }

    @Override
    public int getCount() {
        return bean.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    public void clearSelection(int position) {
        selectedPosition = position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHouer houer;
        if(convertView==null){
            houer= new ViewHouer();
            convertView= LayoutInflater.from(context).inflate(R.layout.dialog_item_xuexiao,null);
            houer.name= (TextView) convertView.findViewById(R.id.tvNianji);
            convertView.setTag(houer);
        }else{
           houer= (ViewHouer) convertView.getTag();
        }
        houer.name.setText(bean.get(position).getName());
        if(selectedPosition==position){
            houer.name.setTextColor(Color.parseColor("#009ff0"));
        }else{
            houer.name.setTextColor(Color.parseColor("#404040"));
        }
        return convertView;
    }
    class ViewHouer{
        TextView name;
    }
}
